
#include "Train.h"


void sendT(int netfd,char * source){
    Train train;
    train.length = strlen(source);
    memcpy(train.data,source,train.length);
    send(netfd,&train,sizeof(train.length)+train.length,MSG_NOSIGNAL);
}



int recvT(int netfd,char** dest){    //只能判断对面断没断开连接，不能判断传没传输完
    *dest = (char *)calloc(1024,sizeof(char));
    Train train;
    int rret1 = recv(netfd,&train.length,sizeof(train.length),MSG_WAITALL);
    if(rret1 == 0){
        return -1;
    }
    int rret2 = recv(netfd,train.data,train.length,MSG_WAITALL);
    if(rret2 == 0){
        return -1;
    }
    memcpy(*dest,train.data,train.length);
    return 0;
}
